package be.novelfaces.component.util.attribute;

import static be.novelfaces.component.util.attribute.AttributeType.AUTOFOCUS;
import static be.novelfaces.component.util.attribute.AttributeType.DISABLED;
import static be.novelfaces.component.util.attribute.AttributeType.FORM_EVENT_ONBLUR;
import static be.novelfaces.component.util.attribute.AttributeType.FORM_EVENT_ONCHANGE;
import static be.novelfaces.component.util.attribute.AttributeType.FORM_EVENT_ONCONTEXTMENU;
import static be.novelfaces.component.util.attribute.AttributeType.FORM_EVENT_ONFOCUS;
import static be.novelfaces.component.util.attribute.AttributeType.FORM_EVENT_ONFORMCHANGE;
import static be.novelfaces.component.util.attribute.AttributeType.FORM_EVENT_ONFORMINPUT;
import static be.novelfaces.component.util.attribute.AttributeType.FORM_EVENT_ONINPUT;
import static be.novelfaces.component.util.attribute.AttributeType.FORM_EVENT_ONINVALID;
import static be.novelfaces.component.util.attribute.AttributeType.FORM_EVENT_ONSELECT;
import static be.novelfaces.component.util.attribute.AttributeType.FORM_EVENT_ONSUBMIT;
import static be.novelfaces.component.util.attribute.AttributeType.GLOBAL_ACCESSKEY;
import static be.novelfaces.component.util.attribute.AttributeType.GLOBAL_CONTENTEDITABLE;
import static be.novelfaces.component.util.attribute.AttributeType.GLOBAL_CONTEXTMENU;
import static be.novelfaces.component.util.attribute.AttributeType.GLOBAL_DIR;
import static be.novelfaces.component.util.attribute.AttributeType.GLOBAL_DRAGGABLE;
import static be.novelfaces.component.util.attribute.AttributeType.GLOBAL_DROPZONE;
import static be.novelfaces.component.util.attribute.AttributeType.GLOBAL_HIDDEN;
import static be.novelfaces.component.util.attribute.AttributeType.GLOBAL_LANG;
import static be.novelfaces.component.util.attribute.AttributeType.GLOBAL_SPELLCHECK;
import static be.novelfaces.component.util.attribute.AttributeType.GLOBAL_STYLE;
import static be.novelfaces.component.util.attribute.AttributeType.GLOBAL_TABINDEX;
import static be.novelfaces.component.util.attribute.AttributeType.GLOBAL_TITLE;
import static be.novelfaces.component.util.attribute.AttributeType.KEYBOARD_EVENT_ONKEYDOWN;
import static be.novelfaces.component.util.attribute.AttributeType.KEYBOARD_EVENT_ONKEYPRESS;
import static be.novelfaces.component.util.attribute.PassThroughAttribute.attr;

import java.util.LinkedHashSet;

import be.novelfaces.component.util.attribute.PassThroughAttribute.Kind;

public class PassThroughAttributes extends LinkedHashSet<PassThroughAttribute> {

	public PassThroughAttributes generic(String name, String property,
			String... events) {
		add(attr(name, property).setEvents(events));
		return this;
	}

	public PassThroughAttributes generic(AttributeType attributeType) {
		add(attr(attributeType));
		return this;
	}

	public PassThroughAttributes uri(AttributeType attributeType) {
		add(attr(attributeType).setKind(Kind.URI));
		return this;
	}

	public PassThroughAttributes uri(String name, String property) {
		add(attr(name, property).setKind(Kind.URI));
		return this;
	}

	public PassThroughAttributes bool(String name, String property) {
		add(attr(name, property).setKind(Kind.BOOLEAN));
		return this;
	}

	public PassThroughAttributes bool(AttributeType attributeType) {
		add(attr(attributeType).setKind(Kind.BOOLEAN));
		return this;
	}

	public PassThroughAttributes withInputTextAttributes() {
		return this.bool(AUTOFOCUS).bool(DISABLED).generic(AttributeType.FORM)
				.generic(AttributeType.LIST).generic(AttributeType.MAXLENGTH)
				.generic(AttributeType.PATTERN)
				.generic(AttributeType.PLACEHOLDER)
				.bool(AttributeType.READONLY).bool(AttributeType.REQUIRED)
				.generic(AttributeType.SIZE);
	}

	public PassThroughAttributes withGlobalAttributes() {
		return this.generic(GLOBAL_ACCESSKEY).generic(GLOBAL_CONTENTEDITABLE)
				.generic(GLOBAL_CONTEXTMENU).generic(GLOBAL_DIR)
				.generic(GLOBAL_DRAGGABLE).generic(GLOBAL_DROPZONE)
				.bool(GLOBAL_HIDDEN).generic(GLOBAL_LANG)
				.generic(GLOBAL_SPELLCHECK).generic(GLOBAL_STYLE)
				.generic(GLOBAL_TABINDEX).generic(GLOBAL_TITLE);
	}

	public PassThroughAttributes withMouseEvents() {
		return this.generic(AttributeType.MOUSE_EVENT_ONCLICK)
				.generic(AttributeType.MOUSE_EVENT_ONDBLCLICK)
				.generic(AttributeType.MOUSE_EVENT_ONDRAG)
				.generic(AttributeType.MOUSE_EVENT_ONDRAGEND)
				.generic(AttributeType.MOUSE_EVENT_ONDRAGENTER)
				.generic(AttributeType.MOUSE_EVENT_ONDRAGLEAVE)
				.generic(AttributeType.MOUSE_EVENT_ONDRAGOVER)
				.generic(AttributeType.MOUSE_EVENT_ONDRAGSTART)
				.generic(AttributeType.MOUSE_EVENT_ONDROP)
				.generic(AttributeType.MOUSE_EVENT_ONMOUSEDOWN)
				.generic(AttributeType.MOUSE_EVENT_ONMOUSEMOVE)
				.generic(AttributeType.MOUSE_EVENT_ONMOUSEOUT)
				.generic(AttributeType.MOUSE_EVENT_ONMOUSEOVER)
				.generic(AttributeType.MOUSE_EVENT_ONMOUSEUP)
				.generic(AttributeType.MOUSE_EVENT_ONMOUSEWHEEL)
				.generic(AttributeType.MOUSE_EVENT_ONSCROLL);
	}

	public PassThroughAttributes withKeyboardEvents() {
		return this.generic(KEYBOARD_EVENT_ONKEYDOWN)
				.generic(KEYBOARD_EVENT_ONKEYPRESS)
				.generic(AttributeType.KEYBOARD_EVENT_ONKEYUP);
	}

	public PassThroughAttributes withFormEvents() {
		return this.generic(FORM_EVENT_ONBLUR).generic(FORM_EVENT_ONCHANGE)
				.generic(FORM_EVENT_ONCONTEXTMENU).generic(FORM_EVENT_ONFOCUS)
				.generic(FORM_EVENT_ONFORMCHANGE)
				.generic(FORM_EVENT_ONFORMINPUT).generic(FORM_EVENT_ONINPUT)
				.generic(FORM_EVENT_ONINVALID).generic(FORM_EVENT_ONSELECT)
				.generic(FORM_EVENT_ONSUBMIT);
	}

}
